<template>
  <div class="app-container">
    <div class="view-container">
      <el-row :gutter="10" class="mb8">
        <el-col :span="23">
          销售报表详情
        </el-col>
        <el-col :span=".5">
          <el-popover placement="bottom" title="筛选列" trigger="click" width="40">            
            <el-checkbox-group v-model="checkedColumns" size="mini">
              <el-checkbox v-for="item in checkBoxGroup" :key="item" :label="item" :value="item"></el-checkbox>
            </el-checkbox-group>
            <div title="筛选列" class="filter-table-col" slot="reference">
              <!-- <i class="el-icon-c-scale-to-original"></i> -->
              <img src="@/assets/img/screening.png" width="25" />
            </div>
          </el-popover>
        </el-col>
      </el-row>
      <el-table :data="salesList" height="calc(100vh - 350px)" :key="reload" border>
        <el-table-column label="序号" type="index" align="center" width="50">
           <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="colData[0].isTrue" label="单据编码" align="center" prop="code" :show-overflow-tooltip="true" width="180px" />
        <el-table-column v-if="colData[1].isTrue" label="出库时间" align="center" prop="endTime" :show-overflow-tooltip="true" width="150px" />
        <el-table-column v-if="colData[2].isTrue" label="客户姓名" align="center" prop="customerName" :show-overflow-tooltip="true" width="150px" />
        <el-table-column v-if="colData[3].isTrue" label="SKU名称" align="center" prop="productName" :show-overflow-tooltip="true" width="200px">
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.orderDetails" :key="index" class="item">
              {{ item.productName }}
            </div>
          </template>
        </el-table-column>
        <el-table-column v-if="colData[4].isTrue" label="规格" align="center" prop="productSpace" :show-overflow-tooltip="true" width="150px">
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.orderDetails" :key="index" class="item">
              {{ item.productSpace }}
            </div>
          </template>
        </el-table-column>
        <el-table-column v-if="colData[5].isTrue" label="单位" align="center" prop="unit" :show-overflow-tooltip="true" width="150px">
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.orderDetails" :key="index" class="item">
              {{ item.unit }}
            </div>
          </template>
        </el-table-column>
        <el-table-column v-if="colData[6].isTrue" label="订单数量" align="center" prop="total" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.orderDetails" :key="index" class="item">
              {{ item.total }}
            </div>
          </template>
        </el-table-column>
        <el-table-column v-if="colData[7].isTrue" label="实际出库数量" align="center" prop="outStore" :show-overflow-tooltip="true" width="100">
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.orderDetails" :key="index" class="item">
              {{ item.outStore }}
            </div>
          </template>
        </el-table-column>
        <el-table-column v-if="colData[8].isTrue" label="发票类型" align="center" prop="invoiceType" :show-overflow-tooltip="true" />
        <el-table-column v-if="colData[9].isTrue" label="发票号" prop="invoice" align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.orderDetails" :key="index" class="item">
              {{ item.invoice }}
            </div>
          </template>
        </el-table-column>
        <el-table-column v-if="colData[10].isTrue" label="状态" align="center" prop="status">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 0" style="color:#13C2C2">待出库</div>
            <div v-if="scope.row.status == 1" style="color:#52C41A">部分出库</div>
            <div v-if="scope.row.status == 2" style="color:#52C41A">已出库</div>
          </template>
        </el-table-column>
        <el-table-column v-if="colData[11].isTrue" label="操作员" prop="updateBy" align="center" :show-overflow-tooltip="true" />
        <el-table-column v-if="colData[12].isTrue" label="备注" prop="remark" align="center" :show-overflow-tooltip="true" />
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { saleReportDetail } from "@/api/system/report/report"

export default {
  name: "outSale",
  data() {
    return {
      total: 0,
      salesList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerName: '',
        productName: '',
        startTime: '',
        endTime: '',
      },
      reload: '',
      // colData中列出表格中的每一列，默认都展示
		  colData: [
        { title: "单据编码", isTrue: true },
        { title: "出库时间", isTrue: true },
        { title: "客户姓名", isTrue: true },
        { title: "SKU名称", isTrue: true },
        { title: "规格", isTrue: true },
        { title: "单位", isTrue: true },
        { title: "订单数量", isTrue: true },
        { title: "实际出库数量", isTrue: true },
        { title: "发票类型", isTrue: true },
        { title: "发票号", isTrue: true },
        { title: "状态", isTrue: true },
        { title: "操作员", isTrue: true },
        { title: "备注", isTrue: true }
      ],
      // 当前选中的多选框，代表当前展示的列
      checkedColumns: ["单据编码", "出库时间", "客户姓名", "SKU名称", "规格", "单位", "订单数量", "实际出库数量", "发票类型", "发票号", "状态", "操作员", "备注"],
      // 多选框的列表，列出表格的每一列
      checkBoxGroup: ["单据编码", "出库时间", "客户姓名", "SKU名称", "规格", "单位", "订单数量", "实际出库数量", "发票类型", "发票号", "状态", "操作员", "备注"]
    }
  },
  created() {
    if(this.$route.query.customerName){
      this.queryParams.customerName = this.$route.query.customerName
    }
    if(this.$route.query.productName){
      this.queryParams.productName = this.$route.query.productName
    }
    if(this.$route.query.startDate){
      this.queryParams.startTime = this.$route.query.startDate
      this.queryParams.endTime = this.$route.query.endDate
    }
    this.getList()
  },
  watch: {
    checkedColumns(val) {
      let arr = this.checkBoxGroup.filter(i => !val.includes(i));
      this.colData.filter(i => {
        if (arr.indexOf(i.title) != -1) {
          i.isTrue = false;
        } else {
          i.isTrue = true;
        }
      });
      this.reload = Math.random()
    }
  },
  methods: {
    // 获取列表
    getList() {
      saleReportDetail(this.addDateRange(this.queryParams)).then(res => {
        this.salesList = res.rows
        this.total = res.total
      })
    }
  }
}
</script>

<style scoped>
.filter-table-col .el-icon-c-scale-to-original{
  font-size: 20px;
  cursor: pointer;
}
::v-deep .el-table__body .el-table__cell{
  padding:0;
}
::v-deep .el-table__body .cell{
  padding: 10px 0;
}
.item{
  height: 25px;
  margin-bottom: 10px;
}
.item:last-child{
  margin-bottom: 0;
}
</style>
